﻿#include <iostream>
#include <string>
#include <map>

using namespace std;

struct Display {
	void operator()(pair<string, double> info) {
		cout << info.first << " " << info.second << ";";
	}
};
int main()
{
	map<string, double> StudentScore;
	StudentScore["zhangsan"] = 95.0;
	StudentScore["lisi"] = 80.0;
	StudentScore.insert(map<string, double>::value_type("wangwu", 88.5));
	//
	遍历
		map
		⽅法⼀
		for (const auto& stu : StudentScore) {
			cout << "name: " << stu.first << " scores: " << stu.second << endl;
		}
	//
	遍历
		map
		⽅法⼆
		for_each
		与运算符重载
		for_each(StudentScore.begin(), StudentScore.end(), Display());
	cout << endl;
	//
	通过迭代器在
		map
		中查找值

		map<string, double>::iterator it;
	it = StudentScore.find("wangwu");
	if (it != StudentScore.end()) {
		cout << (it->second) << endl;
	}
	else {
		cout << "not found" << endl;
	}
	//
	删除迭代器中的值
		erase
		for (it = StudentScore.begin(); it != StudentScore.end(); ++it) {
			if (it->second < 90.0) {
				it = StudentScore.erase(it);
			}
		}
	for_each(StudentScore.begin(), StudentScore.end(), Display());
	cout << endl;
	//find
	找到并删除元素
		StudentScore.erase(it);
	for_each(StudentScore.begin(), StudentScore.end(), Display());
	cout << endl;

	int main()
	{
		map<string, size_t> w_count;
		string word;
		while (cin >> word) {
			++w_count[word];
		}
		for (const auto& w : w_count) {
			cout << w.first << " occurs: " << w.second << ((w.second > 1) ? " time
				s" : " time") << endl;
		}
	}